from django.db import models

# Create your models here.


# 品牌表
# id,    first_name,  name,       logo
# pk,    varchar(10)  varchar(20) varchar(200)
#        默认 None
class Brand(models.Model):
<<<<<<< HEAD
    first_name = models.CharField("品牌首字母", max_length=10)
    name = models.CharField("品牌的名字", max_length=20)
    logo = models.CharField("品牌的logo", max_length=200)

    def __str__(self):
        return self.name
=======
    "品牌"
    first_name = models.CharField(verbose_name="品牌首字母", max_length=10, default=None)
    name = models.CharField(verbose_name="品牌名",max_length=20)
    logo = models.CharField(max_length=200, verbose_name="品牌logo")
>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9

    class Meta:
        db_table = "brand"
        verbose_name_plural = "品牌"

<<<<<<< HEAD
=======
    def __str__(self):
        return self.name

>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9

# 商品种类表
# id    name         cid
# pk varchar(30)   自关联字段
class Cate(models.Model):
<<<<<<< HEAD
    name = models.CharField("商品种类", max_length=30)
    cid = models.ForeignKey("self", on_delete=models.CASCADE, related_name="subs",
                            null=True, blank=True)
=======
    name = models.CharField("商品分类", max_length=30)
    cid = models.ForeignKey("self", on_delete=models.CASCADE, related_name="subs", null=True, blank=True)

    class Meta:
        db_table = 'cate'
        verbose_name_plural = "商品分类"
>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9

    def __str__(self):
        return self.name

<<<<<<< HEAD
    class Meta:
        db_table = "cate"
        verbose_name_plural = "商品种类"


# 频道分组
=======

# 分类分组
>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9
# id    name       cate      group_url    sequence
# pk   varchar(30)  1:1    varchar(100)     int
#						默认http://jd.com    0
class Group(models.Model):
<<<<<<< HEAD
    name = models.CharField("频道组名", max_length=30)
    cate = models.OneToOneField(Cate, on_delete=models.CASCADE, verbose_name="商品类别")
    group_url = models.CharField("频道组的链接地址", max_length=100, default="http://jd.com")
    sequence = models.IntegerField("组内展示顺序", default=0)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "cate_group"
        verbose_name_plural = "频道组"


# SPU 模型类
# id   pk
# name  varchar(20)  'spu'
# brand    外键 "品牌"
# category1     外键  related_name="cate1_spu"  '一级类别'
# category2
# category3
# comment_num  int  default 0    "评论量"
# sales  int  defult 0   "销量"
# desc_detail  text   "详细描述"
# desc_pack   text  "包装信息"
# desc_service text   '售后服务'
class SPU(models.Model):
    name = models.CharField("spu名称", max_length=20)
    brand = models.ForeignKey(Brand, on_delete=models.PROTECT, verbose_name="所属品牌")
    category1 = models.ForeignKey(Cate, on_delete=models.PROTECT,
                                  related_name="cate1_spu", verbose_name="一级类别")
    category2 = models.ForeignKey(Cate, on_delete=models.PROTECT,
                                  related_name="cate2_spu", verbose_name="二级类别")
    category3 = models.ForeignKey(Cate, on_delete=models.PROTECT,
                                  related_name="cate3_spu", verbose_name="三级类别")
    comment_num = models.IntegerField("评论的数量", default=0)
    sales = models.IntegerField("销量", default=0)
    desc_detail = models.TextField("详细描述", default="")
    desc_pack = models.TextField("包装信息", default="")
    desc_service = models.TextField("服务信息", default="")
=======
    name = models.CharField("分类分组", max_length=30)
    cate = models.OneToOneField(Cate, on_delete=models.CASCADE, verbose_name="商品类别")
    group_url = models.CharField("频道的地址", max_length=100, default="http://jd.com")
    sequence = models.IntegerField("组内的顺序", default=0)

    class Meta:
        db_table = 'cate_group'
>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9

    def __str__(self):
        return self.name

<<<<<<< HEAD
    class Meta:
        db_table = "spu"
        verbose_name_plural = "SPU"


# 商品表  即SKU
# name   varchar(100)
# describe varchar(500)
# price  8,2
# stock int default=0
# sales int default =0
# detail text
# image_default  varchar(300)
# is_selling boolean  True
# cate 外键
# spu 外键
class SKU(models.Model):
    name = models.CharField("商品sku", max_length=100)
    describe = models.CharField("商品描述", max_length=500)
    price = models.DecimalField("商品价格", max_digits=8, decimal_places=2)
    stock = models.IntegerField("商品库存", default=0)
    sales = models.IntegerField("商品销量", default=0)
    detail = models.TextField("详情描述", default="")
    image_default = models.CharField("默认图片", max_length=300)
    is_selling = models.BooleanField("是否在售", default=True)
    cate = models.ForeignKey(Cate, on_delete=models.PROTECT, verbose_name="所属类别")
    spu = models.ForeignKey(SPU, on_delete=models.PROTECT, verbose_name="SPU")

    def __str__(self):
        return self.name

    class Meta:
        db_table = "sku"
        verbose_name_plural = "SKU"
=======

>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9
